package br.com.caelum.vraptor.controller;

import java.util.List;

import javax.inject.Inject;

import br.com.caelum.vraptor.dao.AulaDAO;
import br.com.caelum.vraptor.dao.ProfessorDAO;
import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.dao.GenericDAO;
import br.com.caelum.vraptor.entidades.Aula;
@Controller

public class AulaController {

	@Inject
	private Result result;
	
	@Inject
	private GenericDAO<Aula> dao;

	@Inject
	private ProfessorDAO professorDAO; 
	public void add(){
		result.include("professorList", professorDAO.find());
	}
	
	
	public List<Aula> list(){
		return dao.find();	
	}
	
	
	public void save(Aula aula){
		
		dao.save(aula);
		
		result.redirectTo(IndexController.class).index();
	}
	
	public Aula edit(Integer id){
		return dao.find(id);
	}
	
	public void delete(int id){
		Aula aula = new Aula();
		aula.setId(id);
		dao.delete(aula);
		result.redirectTo(ProfessorController.class).list();
	}
	
}

